package cn.terminus.biz.customer.contractrentdiscountclause;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractrentdiscountclause.dto.*;
import cn.terminus.data.customer.contractrentdiscountclause.dao.ContractRentDiscountClauseDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同优惠条款(ContractRentDiscountClause)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:15:30
 */
@Component
public class ContractRentDiscountClauseManager extends AbstractTerminusManager {
    @Autowired
    private ContractRentDiscountClauseDao contractRentDiscountClauseDao;

    public Integer add(ContractRentDiscountClauseNewDto dto) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractRentDiscountClauseManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractRentDiscountClauseEditDto dto) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractRentDiscountClauseManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractRentDiscountClauseResultDto> gets(ContractRentDiscountClauseGetsDto dto) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractRentDiscountClauseManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractRentDiscountClauseResultDto> query(ContractRentDiscountClauseQueryDto dto) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractRentDiscountClauseManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractRentDiscountClauseDeleteDto dto) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractRentDiscountClauseManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractRentDiscountClauseResultDto> page(ContractRentDiscountClauseQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractRentDiscountClauseResultDto> result = (Page<ContractRentDiscountClauseResultDto>) contractRentDiscountClauseDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractRentDiscountClauseResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractRentDiscountClauseManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer insertBatch(List<ContractRentDiscountClauseNewDto> dtos) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.insertBatch(dtos);
        } catch (Exception e) {
            logger.error("contractRentDiscountClauseDao insertBatch失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractRentDiscountClauseDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("contractRentDiscountClauseDao insertBatch失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
